package top.zhanglingxi.algorithms;

import lombok.Data;
import lombok.NonNull;
import top.zhanglingxi.enums.PointEnum;

/**
 * 迷宫
 * @author ZWX
 */
@Data
public class Labyrinth {
    /**
     * 迷宫长
     */
    private int length;

    /**
     * 迷宫宽
     */
    private int width;

    /**
     * 点数组
     */
    @NonNull
    private Point[][] points;

    /**
     * 起点
     */
    private Point start;

    /**
     * 终点
     */
    private Point end;

    /**
     * 构建迷宫
     * @param length 迷宫场地
     * @param width 迷宫宽度
     */
    public Labyrinth(int length, int width) {
        this.length = length;
        this.width = width;
        // 初始化点数组
        this.points = new Point[length][width];
        for (int i = 0; i < length; i++) {
            for (int j = 0; j < width; j++) {
                this.points[i][j] = new Point(i, j, PointEnum.WHITE);
            }
        }
    }

    @Override
    public String toString() {
        StringBuilder builder = new StringBuilder();
        for (int y = 0; y < length; y++) {
            for (int x = 0; x < width; x++) {
                if (this.points[x][y] != null) {
                    builder.append(this.points[x][y].toString());
                }
                if (x != width - 1) {
                    builder.append(" ");
                }
            }
            if (y != length - 1) {
                builder.append("\n");
            }
        }
        return builder.toString();
    }
}
